package com.gnerv.oauth.cuntom;

import com.gnerv.oauth.entity.CustomUserDetails;
import com.gnerv.oauth.mapper.UserMapper;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CustomUserDetailsService implements UserDetailsService {

    @Resource
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        CustomUserDetails customUserDetails = userMapper.selectUserByAccount(account);
        return customUserDetails;
    }

    public UserDetails loadUserByUsername(String account, String loginType) throws UsernameNotFoundException {
        if ("phone".equals(loginType)) {
            CustomUserDetails customUserDetails = userMapper.selectUserByNumber(account);
            return customUserDetails;
        }
        CustomUserDetails customUserDetails = userMapper.selectUserByAccount(account);
        return customUserDetails;
    }

}
